import csv

def load_data(file_path):
    """
    Load CSV data into NumPy array
    Columns: student_id, name, math_score, english_score, python_score
    Return: 2D NumPy array of shape (students, 3) containing scores
    """
    # 加载CSV数据到NumPy数组
    # 列：student_id, name, math_score, english_score, python_score
    # 返回：形状为(学生数, 3)的二维数组，包含三科成绩
    scores = []
    with open(file_path, 'r') as file:
        reader = csv.reader(file)
        next(reader)  # 跳过标题行
        for row in reader:
            scores.append([float(row[2]), float(row[3]), float(row[4])])
    return np.array(scores)




    pass

def calculate_statistics(data):

    """
    Calculate required statistics for each subject
    Return: Dictionary containing {
        'means': [math_mean, english_mean, python_mean],
        'medians': [math_median, english_median, python_median],
        'variances': [math_var, english_var, python_var],
        'stds': [math_std, english_std, python_std]
    }
    """
    # 计算每科的统计指标
    # 返回：包含平均值、中位数、方差、标准差的字典
    means = np.round(np.mean(data, axis=0), 1)
    medians = np.round(np.median(data, axis=0), 1)
    variances = np.round(np.var(data, axis=0), 1)
    stds = np.round(np.std(data, axis=0), 1)
    return {
        'means': means,
        'medians': medians,
        'variances': variances,
        'stds': stds
    }






    pass

def print_results(stats):
    """
    Print results in EXACTLY this format:
    Math:
        Average: 85.0
        Median: 86.0
        Variance: 25.0
        Standard Deviation: 5.0
    English:
        ...
    Best Subject: Math
    Most Consistent Subject (Lowest Std): English (4.2)
    """
    # 严格按指定格式打印结果
    # 输出示例格式见上方注释
    subjects = ['Math', 'English', 'Python']
    for i, subject in enumerate(subjects):
        print(f"{subject}:")
        print(f"    Average: {stats['means'][i]}")
        print(f"    Median: {stats['medians'][i]}")
        print(f"    Variance: {stats['variances'][i]}")
        print(f"    Standard Deviation: {stats['stds'][i]}")
        print()
    best_subject_index = np.argmax(stats['means'])
    most_consistent_index = np.argmin(stats['stds'])
    print(f"Best Subject: {subjects[best_subject_index]}")
    print(f"Most Consistent Subject (Lowest Std): {subjects[most_consistent_index]} ({stats['stds'][most_consistent_index]})")



    pass

def main():
    data = load_data('scores.csv')
    
    stats = calculate_statistics(data)
    
    print_results(stats)

if __name__ == "__main__":
    main()

